import os
import sys
import start
import start_daemonoff


def stop_proc():
    ret = os.system("python stop.py")
    if ret != 0:
        print ("stop the nginx-process faild!")
        sys.exit()

def star_new(params):
    ngxconf = params[1]
    is_deamonoff = params[2] if len(params) > 2 else None
    if is_deamonoff:
        start_daemonoff.execute(ngxconf)
        return 
    start.execute(ngxconf)

if __name__ == "__main__":
    stop_proc()
    if len(sys.argv) <= 1:
        sys.exit()
    star_new(sys.argv)
